package com.sz.common.core.system.service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Function: TODO: ADD FUNCTION <br>
 * Author: Charles. <br>
 * Date: 2017-04-12 10:11:00.
 */
public interface SysUserSupport {

    List<UserModel> getUsersById(List<Integer> userIdList);

    List<UserModel> getUsersByAccount(List<String> accountList);

    default UserModel getUserById(int userId) {
        List<Integer> list = Arrays.asList(userId);
        List<UserModel> users = getUsersById(list);
        if (users != null && users.size() > 0) {
            return users.get(0);
        }
        return null;
    }

    default UserModel getUserByAccount(String account) {
        List<String> list = Arrays.asList(account);
        List<UserModel> users = getUsersByAccount(list);
        if (users != null && users.size() > 0) {
            return users.get(0);
        }
        return null;
    }

    default Map<Integer, UserModel> getUsersMapById(List<Integer> userIdList) {
        List<UserModel> list = getUsersById(userIdList);
        Map<Integer, UserModel> map = new HashMap<>();
        if (list != null && list.size() > 0) {
            for (UserModel um : list) {
                map.put(um.getUserId(), um);
            }
        }
        return map;
    }

    default Map<String, UserModel> getUsersMapByAccount(List<String> accountList) {
        List<UserModel> list = getUsersByAccount(accountList);
        Map<String, UserModel> map = new HashMap<>();
        if (list != null && list.size() > 0) {
            for (UserModel um : list) {
                map.put(um.getAccountName(), um);
            }
        }
        return map;
    }
}
